﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using uzing;
using System.Net;

namespace example_tcp_gui_client
{
    public partial class FormTcpClient : Form
    {
        public FormTcpClient()
        {
            InitializeComponent();

            IPHostEntry ipEntry = Dns.GetHostByName(Dns.GetHostName());
            labelIpAddr.Text = "My IP Address : " + ipEntry.AddressList[0].ToString();
        }


        CTcpClientSync client;
        int dataSize;
        byte[] buffer;
        ASCIIEncoding encoder;

        private void btnCon_Click(object sender, EventArgs e)
        {
            client = new CTcpClientSync(4096);
            client.ConnectToServer(tbIpAddr.Text, Int32.Parse(tbPort.Text));
            dataSize = 1024;
            buffer = new byte[dataSize];
            encoder = new ASCIIEncoding();
            btnCon.Enabled = false;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            byte[] tmpBuf = encoder.GetBytes(tbMsg.Text);
            tmpBuf.CopyTo(buffer, 0);
            client.SendData(buffer, 0, dataSize);
        }

    }
}
